package com.ruoyi.project.instrument.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.instrument.domain.InsAlarmRecord;
import com.ruoyi.project.instrument.service.IInsAlarmRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 仪器报警信息记录Controller
 *
 * @author taney
 * @date 2020-06-08
 */
@AllArgsConstructor
@RestController
@RequestMapping("/instrument/alarmRecord" )
public class InsAlarmRecordController extends BaseController {

    private final IInsAlarmRecordService iInsAlarmRecordService;

    /**
     * 查询仪器报警信息记录列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:alarmRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsAlarmRecord insAlarmRecord)
    {
        startPage();
        LambdaQueryWrapper<InsAlarmRecord> lqw = new LambdaQueryWrapper<InsAlarmRecord>();
        if (insAlarmRecord.getAlarmTime() != null){
            lqw.eq(InsAlarmRecord::getAlarmTime ,insAlarmRecord.getAlarmTime());
        }
        if (StringUtils.isNotBlank(insAlarmRecord.getLevel())){
            lqw.eq(InsAlarmRecord::getLevel ,insAlarmRecord.getLevel());
        }
        if (insAlarmRecord.getCode() != null){
            lqw.eq(InsAlarmRecord::getCode ,insAlarmRecord.getCode());
        }
        if (StringUtils.isNotBlank(insAlarmRecord.getCuowu())){
            lqw.eq(InsAlarmRecord::getCuowu ,insAlarmRecord.getCuowu());
        }
        if (insAlarmRecord.getCishu() != null){
            lqw.eq(InsAlarmRecord::getCishu ,insAlarmRecord.getCishu());
        }
        List<InsAlarmRecord> list = iInsAlarmRecordService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出仪器报警信息记录列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:alarmRecord:export')" )
    @Log(title = "仪器报警信息记录" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(InsAlarmRecord insAlarmRecord) {
        LambdaQueryWrapper<InsAlarmRecord> lqw = new LambdaQueryWrapper<InsAlarmRecord>(insAlarmRecord);
        List<InsAlarmRecord> list = iInsAlarmRecordService.list(lqw);
        ExcelUtil<InsAlarmRecord> util = new ExcelUtil<InsAlarmRecord>(InsAlarmRecord. class);
        return util.exportExcel(list, "alarmRecord" );
    }

    /**
     * 获取仪器报警信息记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('instrument:alarmRecord:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iInsAlarmRecordService.getById(id));
    }

    /**
     * 新增仪器报警信息记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:alarmRecord:add')" )
    @Log(title = "仪器报警信息记录" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsAlarmRecord insAlarmRecord) {
        return toAjax(iInsAlarmRecordService.save(insAlarmRecord) ? 1 : 0);
    }

    /**
     * 修改仪器报警信息记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:alarmRecord:edit')" )
    @Log(title = "仪器报警信息记录" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsAlarmRecord insAlarmRecord) {
        return toAjax(iInsAlarmRecordService.updateById(insAlarmRecord) ? 1 : 0);
    }

    /**
     * 删除仪器报警信息记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:alarmRecord:remove')" )
    @Log(title = "仪器报警信息记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iInsAlarmRecordService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
